package com.ym.b2b.complaint.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.ym.b2b.commons.controller.BaseController;
import com.ym.b2b.commons.log.CusLog;
import com.ym.b2b.complaint.service.EmBReplyService;
import com.ym.b2b.complaint.sqlbean.EmBReply;
import com.zc.commons.base.Page;
import com.zc.commons.base.Result;

@Controller
@RequestMapping("/complaint")
public class ManagerReplyController extends BaseController {

    @Autowired
    private EmBReplyService emBReplyService;

    // 列表查询
    @RequestMapping("searchPageEmBReply.do")
    @ResponseBody
    public Result searchPageEmBReply(EmBReply emBReply, Page<EmBReply> page, HttpServletRequest req) {
    	CusLog.writeLog(getManagerTokenUser(req).getUserName() + " 列表获取投诉的反馈内容: " + JSON.toJSONString(emBReply), "USER", 2);
        Result result = new Result();
        result = emBReplyService.searchPageEmBReply(emBReply, page);
        return result;
    }

    // 获取单条记录内容
    @RequestMapping("searchEmBReply.do")
    @ResponseBody
    public EmBReply searchEmBReply(EmBReply emBReply, HttpServletRequest req) {
    	CusLog.writeLog(getManagerTokenUser(req).getUserName() + " 获取投诉的反馈内容: " + JSON.toJSONString(emBReply), "USER", 2);
        EmBReply result = new EmBReply();
        result = emBReplyService.searchEmBReply(emBReply);
        return result;
    }

    // 删除记录内容
    @RequestMapping("deleteEmBReply.do")
    @ResponseBody
    public Result deleteEmBNews(EmBReply emBReply, HttpServletRequest req) {
    	CusLog.writeLog(getManagerTokenUser(req).getUserName() + " 删除客户反馈回复: " + JSON.toJSONString(emBReply), "USER", 2);
        Result result = new Result();
        try {
            emBReplyService.deleteEmBReply(emBReply.getReplyId());
        } catch (Exception e) {
            // TODO: handle exception
            result.setCode("100");
            return result;
        }
        result.setCode("200");
        return result;
    }

    // 删除多条记录内容
    @RequestMapping("deleteMultipleEmBReply.do")
    @ResponseBody
    public Result deleteMultipleEmBReply(String replyIdList, HttpServletRequest req) {
    	CusLog.writeLog(getManagerTokenUser(req).getUserName() + " 批量删除客户反馈回复: " + replyIdList, "USER", 2);
        Result result = new Result();
        try {
            emBReplyService.deleteMultipleEmBReply(replyIdList);
        } catch (Exception e) {
            // TODO: handle exception
            result.setCode("100");
            return result;
        }
        result.setCode("200");
        return result;
    }

    // 更新记录
    @RequestMapping("updateEmBReply.do")
    @ResponseBody
    public Result updateEmBNews(EmBReply emBReply, HttpServletRequest req) throws DataAccessException {
    	CusLog.writeLog(getManagerTokenUser(req).getUserName() + " 更新客户反馈回复: " + JSON.toJSONString(emBReply), "USER", 2);
        Result result = new Result();
        result = emBReplyService.updateEmBReply(emBReply);
        return result;
    }

    // 新增记录
    @RequestMapping("insertEmBReply.do")
    @ResponseBody
    public Result insertEmBReply(EmBReply emBReply, HttpServletRequest req) {
    	CusLog.writeLog(getManagerTokenUser(req).getUserName() + " 新增客户反馈回复: " + JSON.toJSONString(emBReply), "USER", 2);
        emBReply.setReplyUser(getManagerTokenUser(req).getUserName());
        Result result = new Result();
        result = emBReplyService.insertEmBReply(emBReply);
        return result;
    }

    // 批量更新记录
    @RequestMapping("updateEmBReplyBat.do")
    @ResponseBody
    public Result updateEmBNewsBat(EmBReply emBReply, HttpServletRequest req) throws DataAccessException {
    	CusLog.writeLog(getManagerTokenUser(req).getUserName() + " 批量更新客户反馈回复: " + JSON.toJSONString(emBReply), "USER", 2);
        Result result = new Result();
        result = emBReplyService.updateEmBReplyBat(emBReply);
        return result;
    }

}
